package ui;

import java.io.IOException;

import utilities.FileManagement;
import client.HTTPClient;

public class Chat {

	HTTPClient client = new HTTPClient();
	String[][] users;
	public void sendMessage(String Message,String To){ // name[enter] message
		try {
			client.send(Message,"192.168.0.39");
		} catch (IOException e) {
			System.out.println("panic");
			e.printStackTrace();
		}
	}
//	public String[] pulse(){
//		String[][] data;
//		data[0] = this.getMessage();
//	}
//	public String[] getMessage(){
//		return client.askForMessages();
//	}
	
	public String getNamesList(){ //Command : list
		this.syncNamesList();
		String namesList = "";
		for(int i = 0; i<= this.users.length; i++){
			namesList += this.users[i][0]+"\n\t";
		}
		return namesList;
	}
	
	private String resolveTo(String To){
		this.syncNamesList();
		
		for(int i = 0; i<= this.users.length; i++){
			
			if(this.users[i][0].equals(To)){
				return this.users[i][1];
			}
		}
		
		return "172.0.0.1"; //halb
	}
	
	private void syncNamesList(){
		FileManagement fManager = new FileManagement();
		this.users = fManager.read("users.txt");
	}
	public boolean registered(){
		return false;
	}
	
	public void register(String FirstUser, String name){
		//Send name to FirstUser
		
	}
	
}
